﻿using log4net;
using LSFTP;
using Rainbow.common;
using Rainbow.model;
using Rainbow.utils;

namespace Rainbow.core
{
    public enum AppStatus
    {
        STARTED,
        QUIT
    }

    public class TW_App
    {
        private static ILog logger = LogManager.GetLogger(typeof(TW_App));

        public static string PROJECT_NAME = "彩虹";
        public static string COMPANY_NAME = "北京通为科技有限公司";

        //public static string VERSION = "1.0.0";
        //public static string VERSION = "1.0.1"; // 添加数据转换功能
        public static string VERSION = "1.0.2"; // 修复可以上传下载0字节文件

        public static AppStatus appStatus = AppStatus.STARTED;

        /// <summary>
        /// 状态栏
        /// </summary>
        public static StatusBarProperty statusBarInfo = new StatusBarProperty();

        /// <summary>
        /// FTP操作类
        /// </summary>
        public static IFTP ftp = null;
        /// <summary>
        /// SQLite操作类
        /// </summary>
        public static SQLiteHelper helper;

        /// <summary>
        /// 全局配置
        /// </summary>
        public static GlobalSetting globalSetting;

        /// <summary>
        /// 连接管理文件
        /// </summary>
        public static ConnectInfoCollection connectInfos;


        public static FileManager fileManager = new FileManager();


        public TW_App()
        {

        }

        public static int Init()
        {
            var fi = new System.IO.FileInfo(fileManager.logConfigFile);
            log4net.Config.XmlConfigurator.Configure(fi);

            globalSetting = new GlobalSetting();
            int rn2 = globalSetting.Load();
            if (rn2 == -1)
            {
                string errmsg = string.Format("全局配置加载失败");
                logger.ErrorFormat(errmsg);
                return -3;
            }

            connectInfos = new ConnectInfoCollection();
            connectInfos.Load();

            return 0;
        }
    }
}
